package com.maple.controller

import com.alibaba.fastjson.JSON
import com.google.gson.Gson
import com.maple.common.ResultUtil
import com.maple.model.{Grade, JdbcRepo}
import com.maple.util.FileUtil
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.{GetMapping, ResponseBody, RestController}

/**
  * author: HuaZhe Ray
  *
  * describe: Analyze Controller
  *
  * createDate: 2017/12/15
  * createTime: 10:21
  *
  */
@Controller
class AnalyzeController {

  @GetMapping(Array("/scala"))
  @ResponseBody
  def indexGreeting(): Any ={
    val students = JdbcRepo.queryStudents().toString()
    ResultUtil.success(students)
  }

  @GetMapping(Array("/analyse"))
  def analyzeIndex(): String ={
    "analyse"
  }
  @GetMapping(Array("/start/analyse"))
  @ResponseBody
  def analyze(): Any ={
    val students = JdbcRepo.queryStudents().toString()
    ResultUtil.success(students)
  }


  @GetMapping(Array("/analyse/show-grade"))
  @ResponseBody
  def queryGrades(): Any ={
    val gradesName:List[String] = JdbcRepo.queryGrades().map(_.name)
    val gson = new Gson
    ResultUtil.success(gson.toJson(gradesName.toString))

  }

  @GetMapping(Array("/analyse/generate"))
  @ResponseBody
  def generateFile(): Any ={
    val file = FileUtil.writeLogToFile("test by maple")
    "AAA"
  }


}
